local sk = fk.CreateSkill {
  name = "hx__AWEC_with",
}

Fk:loadTranslationTable{
  ["hx__AWEC_with"] = "跟牌",
}

sk:addEffect("active", {
  mute = true,
  min_card_num = 0,
  max_card_num = function(self, player)
    local room = Fk:currentRoom()
    local nextCard = room:getBanner("hx__AWEC_mode-NextCard") or {}
    local lordid = room:getBanner("hx__AWEC_mode-Lord")
    local lord = room:getPlayerById(lordid)
    local max = math.max(lord:getHandcardNum() - #nextCard, 0)
    return max
  end,
  target_num = 0,
  can_use = Util.TrueFunc,
  card_filter = function(self, player, to_select, selected)
    local room = Fk:currentRoom()
    local numbers = room:getBanner("hx__AWEC_mode-CanNum") or {}
    local nextCard = room:getBanner("hx__AWEC_mode-NextCard") or {}
    local lordid = room:getBanner("hx__AWEC_mode-Lord")
    local lord = room:getPlayerById(lordid)
    local max = math.max(lord:getHandcardNum() - #nextCard, 0)
    return #selected < max and Fk:getCardById(to_select).name ~= "hx__joker" and Fk:getCardById(to_select).name ~= "hx__joker2"and
    table.contains(numbers, Fk:getCardById(to_select).number)
  end,
})

sk:addAI({
  think = function(self, ai)
    local player = ai.player
    local cards = ai:getEnabledCards(".|.|.|hand|.|.|.")

    if #cards > 0 then
      cards = ai:getChoiceCardsByKeepValue(cards, #cards, function(value) return value < 45 end)
      return { cards = cards }, ai:getBenefitOfEvents(function(logic)
        logic:throwCard(cards, self.skill.name, player, player)
        logic:drawCards(player, #cards + 2, self.skill.name)
      end)
    end
end,
})


return sk
